package org.chen.user.controller;

import org.chen.mvc.annotation.Controller;
import org.chen.mvc.annotation.PostMapping;
import org.chen.mvc.annotation.RequestMapping;
import org.chen.mvc.annotation.RequestMethod;
import org.chen.spring.core.annotation.Autowired;
import org.chen.user.aop.ApiLog;
import org.chen.user.domain.R;
import org.chen.user.domain.UserDomain;
import org.chen.user.service.UserService;

/**
 * 用户控制器
 *
 * @author Chen
 * @since 2023/6/7 13:58
 */

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiLog("根据id查询用户")
    @RequestMapping(value = "/findUserById", method = {RequestMethod.POST, RequestMethod.GET})
    public R<UserDomain> findUserById(String id) {
        UserDomain userById = userService.findUserById(id);
        return R.ok(userById);
    }

    @ApiLog("添加用户")
    @PostMapping(value = "/addUser")
    public R<UserDomain> addUser(String phone, String password, String nickname) {
        boolean flag = userService.addUser(phone, password, nickname);
        return flag ? R.ok() : R.fail();
    }

}
